package com.wswy.wzcx.ui.njdb

import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.RectF
import android.support.v4.content.ContextCompat
import android.text.TextPaint
import com.blankj.utilcode.util.SizeUtils
import com.wswy.wzcx.AppContext
import com.wswy.wzcx.R
import com.wswy.wzcx.widget.drawable.BaseDrawable

class NumDrawable(var num:String,bgColor :Int = ContextCompat.getColor(AppContext.getContext(), R.color.color_orange)) : BaseDrawable() {

    private val textPaint = TextPaint(Paint.ANTI_ALIAS_FLAG)
    private val rectF = RectF()

    init {

        setBounds(0,0,SizeUtils.dp2px(18f),SizeUtils.dp2px(18f))

        textPaint.color = Color.WHITE
        textPaint.textSize = SizeUtils.sp2px(12f).toFloat()
        textPaint.textAlign = Paint.Align.CENTER

        paint.color = bgColor
        paint.style = Paint.Style.FILL
    }

    override fun draw(canvas: Canvas) {
        rectF.set(rect)
        canvas.drawCircle(rectF.centerX(),rectF.centerY(),rectF.width()/2f,paint)

        val baseline = (rectF.height() - textPaint.fontMetrics.bottom - textPaint.fontMetrics.top)/2f

        canvas.drawText(num,rectF.centerX(),baseline,textPaint)

    }
}